<template>
	<view class="home">
		<uni-nav-bar shadow left-icon="left" title="我没有公众号" @clickLeft="back" />
		<view class="form_box">
			<uni-section title="天气设置" type="line">
				<view class="example">
					<!-- 基础表单校验 -->
					<uni-forms ref="valiForm" :v-model="valiFormData" labelWidth="90px" labelAlign="right">
						<uni-forms-item label="openId" required name="openId" >
							<uni-easyinput :disabled="true"  v-model="valiFormData.openId" placeholder="请输入openId" />
						</uni-forms-item>
					</uni-forms>
					<button type="primary" @click="submit()">提交</button>
				</view>
			</uni-section>
		</view>
		<view style="height: 100%;">
			<uni-popup ref="popup" type="bottom">
				<text>{{result}}</text>
				<button @click="close">关闭</button>
			</uni-popup>
		</view>
	</view>
</template>
<script>
	import {
		APP_ID,
		SECRET
	} from '../../config/projectConfig.js'
	export default {
		data() {
			return {
				searchVal: '',
				loading: false,
				isPop: false,
				itemData: '',
				popType: '',
				result: '',
				// 校验表单数据
				valiFormData: {
					openId: '',
				},
				userInfo: '',

			}
		},
		onLoad(option) {
			if (option.userInfo) {
				this.userInfo = JSON.parse(option.userInfo)
			}
		},

		mounted() {
			this.valiFormData.openId = this.userInfo ? this.userInfo.openid : ''
		},
		methods: {
			back() {
				let pages = getCurrentPages()
				if (pages.length > 1) {
					uni.navigateBack({
						delta: 1
					})
				} else {
					uni.reLaunch({
						url: "/pages/index/index"
					})
				}
			},
			open() {
				this.$refs.popup.open('top')
			},
			close() {
				this.$refs.popup.close()
			},
			// 	确认提交
			submit() {
				let that = this;
				console.log(this.valiFormData.openId);
				that.$refs.valiForm.validate().then(res => {
					uni.showLoading({
						title: '正在提交...'
					})
					uni.showLoading({
						title: '配置生成中...'
					})
					// that.valiFormData.openId = that.userInfo.openid
					setHasData({openid: that.valiFormData.openId}).then(res => {
						uni.showToast({
							title: `设置成功`,
							icon: 'success',
							success() {
								uni.reLaunch({
									url: '/pages/success/success?setData=' + JSON
										.stringify(that.valiFormData)
								})
							}
						})
						uni.hideLoading()
					}).catch(() => {
						uni.hideLoading()
					})
				}).catch(err => {
					console.log('err', err);
				})
			},
		}
	}
</script>

<style>
	/* #ifndef H5 */
	/* page {
	padding-top: 85px;
} */
	/* #endif */
	page {
		background-color: #fff;
	}

	.example {
		padding: 1rem;
	}
</style>
